package com.example.mykotlin.model.entity

import com.example.mykotlin.base.valid.Insert
import com.example.mykotlin.base.valid.Update
import com.fasterxml.jackson.annotation.JsonFormat
import com.mybatisflex.annotation.Id
import io.swagger.v3.oas.annotations.media.Schema
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import java.time.LocalDateTime

@Schema(name = "AuditLog", title = "审计日志表")
open class AuditLog(
    @Schema(title = "唯一标识每条请求日志的ID")
    @Id
    @field:Min(value = 1, message = "主键不能小于1", groups = [Update::class])
    @field:NotNull(message = "不能为空", groups = [Update::class])
    var id: Long? = null,

    @Schema(title = "执行操作的用户ID")
    var userId: Long? = null,

    @Schema(title = "执行操作的用户名")
    @field:Size(max = 32, message = "长度不能超过32")
    var username: String? = null,

    @Schema(title = "执行操作时的IP地址")
    @field:Size(max = 45, message = "长度不能超过45")
    @field:NotBlank(message = "不能为空", groups = [Insert::class])
    var ipAddress: String? = null,

    @Schema(title = "执行操作时的服务器IP地址")
    @field:Size(max = 45, message = "长度不能超过45")
    @field:NotBlank(message = "不能为空", groups = [Insert::class])
    var serviceIpAddress: String? = null,

    @Schema(title = "被操作接口资源ID")
    @field:Size(max = 32, message = "长度不能超过32")
    @field:NotBlank(message = "不能为空", groups = [Insert::class])
    var apiId: String? = null,

    @Schema(title = "被操作接口资源名称")
    @field:Size(max = 255, message = "长度不能超过255")
    @field:NotBlank(message = "不能为空", groups = [Insert::class])
    var apiName: String? = null,

    @Schema(title = "变化的数据，以JSON格式存储")
    var changeValue: String? = null,

    @Schema(title = "记录创建的时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @field:NotNull(message = "不能为空", groups = [Insert::class])
    var createTime: LocalDateTime? = null,



)